package com.zmzncs.lmtc.module.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.order.pojo.orderreserve.*;
import com.zmzncs.lmtc.module.order.service.ParkReserveRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 预约记录表 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-12-14
 */
@Api(tags = {"预约记录"})
@RestController
@RequestMapping("/order-reserve/park-reserve-record")
@Validated
public class ParkReserveRecordController {

    @Autowired
    private ParkReserveRecordService parkReserveRecordService;


    @ApiOperation(value = "审核预约")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id", value="预约id", required = true),
        @ApiImplicitParam(name="status", value="状态（2：预约通过 3：预约驳回）", required = true),
    })
    @PostMapping("audit-reserve/{id}/{status}")
    public Rest auditReserve(@PathVariable Long id, @PathVariable Integer status){
        parkReserveRecordService.auditReserve(id, status);

        return RestUtil.success();
    }

    @ApiOperation(value = "查询预约记录信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name="pageNum", value="页码", required = true),
            @ApiImplicitParam(paramType="query", name="pageSize", value="页长", required = true),
            @ApiImplicitParam(paramType="query", name="parkId", value="车场ID", required = true),
            @ApiImplicitParam(paramType="query", name="status", value="状态"),
    })
    @GetMapping("get-reserve-record")
    public Rest<IPage<ParkReserveRecordTableVO>> getReserveRecord(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
                                                                  @NotNull Long parkId,Integer status){
        IPage<ParkReserveRecordDTO> reserveRecord = parkReserveRecordService.getReserveRecord(pageNum, pageSize, parkId,status);
        PageInfo<ParkReserveRecordTableVO> pageInfo = JsonUtil.pageTransform(reserveRecord, ParkReserveRecordTableVO.class);
        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "昨天、今天、本周、本月的预约缴费")
    @ApiImplicitParams({
            @ApiImplicitParam(name="parkId", value="停车场id"),
            @ApiImplicitParam(name="dateType", value="时间类型（1：昨天、2：今天、3：本周、4：本月，5：本年）"),
    })
    @GetMapping("get-reserve-amount-by-date")
    public Rest<String> getReserveAmountByDate( @RequestParam Long parkId, @RequestParam Integer dateType) {
        String paidAmountByDate = parkReserveRecordService.getReserveAmountByDate(parkId, dateType);

        return RestUtil.success(paidAmountByDate);
    }

}
